#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
using namespace std;
using i64 = long long;

const int N = 1e5 + 10, INF = 0x3f3f3f3f;
const int mod = 1e9+7;
i64 n, a, b, c, d;

i64 qmi(i64 a, i64 b)
{
    i64 res = 1;
    while (b) {
        if (b & 1) res = a * res % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void solve()
{
    i64 inv2 = qmi(2, mod - 2);
    //cout << inv2 << endl;
    while (cin >> n >> a >> b >> c >> d) {
        i64 res = 0, ans = 0,cnt=0;
        ans = ((a + b) % mod + (c + d) % mod) % mod * n % mod;
        //ans = ans * n % mod;
        //cout <<"ans"<< ans << endl;
        res = (a*b % mod + b*c % mod +
            a*d % mod + c*d % mod) % mod;
        //cout << "res" << res << endl;
        cnt = n * (n - 1) % mod * inv2 % mod;
        res = (res * cnt) % mod;
        //cout << "res" << res << endl;
        ans = (ans + res + 1) % mod;
        cout << ans << '\n';
    }
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
#define ONLINE_JUDGE
#ifndef ONLINE_JUDGE
    std::istringstream in(R"()");
    std::cin.rdbuf(in.rdbuf());
#endif
    int T = 1;
    //cin>>T;
    for (int i = 1;i <= T;i++) {
        solve();
    }
}